package com.zh.mediaservice.controller.Doctor;

import com.zh.mediacommon.context.BaseContext;
import com.zh.mediacommon.result.Result;
import com.zh.mediapojo.dto.DoctorLoginDTO;
import com.zh.mediapojo.dto.DoctorUpdatePasswordDTO;
import com.zh.mediapojo.entity.User;
import com.zh.mediapojo.vo.DoctorLoginVO;
import com.zh.mediaservice.service.DoctorService;
import com.zh.mediaservice.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/doctor")
@Slf4j
public class DoctorController {

    /*
    * 医生登录
    * */
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private UserService userService;
    @PostMapping("/log")
    public Result<DoctorLoginVO> log(@RequestBody DoctorLoginDTO doctorLoginDTO){
        DoctorLoginVO doctorLoginVO = doctorService.login(doctorLoginDTO);
        return Result.success(doctorLoginVO);
    }

    @PutMapping("/FirstUpdatePassword")
    public Result<String> FirstUpdatePassword(@RequestBody DoctorUpdatePasswordDTO depositPasswordDTO){
       log.info("修改密码{}",depositPasswordDTO);
       Long id = BaseContext.getCurrentId();
       if(id!=null) {
           int i = id.intValue();
           depositPasswordDTO.setId(i);
           log.info("baseId");
       }
        doctorService.updatePassword(depositPasswordDTO);
        return Result.success("密码修改成功");
    }
    @GetMapping("/getUserInfo/{userId}")
    public Result<User> getUserInfo(@PathVariable("userId") Long userId){
        return Result.success(userService.getChatUserInfo(userId));
    }
}
